package com.ynu.appuser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ynu.appuser.domain.appuser.MdUser;
import com.ynu.appuser.service.IMdUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * App用户Controller
 *
 * @author TangZheng
 * @date 2022-12-02
 */
@RestController
@RequestMapping("/push/user")
public class MdUserController extends BaseController
{
    @Autowired
    private IMdUserService mdUserService;

    /**
     * 查询App用户列表
     */
    @PreAuthorize("@ss.hasPermi('push:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(MdUser mdUser)
    {
        startPage();
        List<MdUser> list = mdUserService.selectMdUserList(mdUser);
        return getDataTable(list);
    }

    /**
     * 导出App用户列表
     */
    @PreAuthorize("@ss.hasPermi('push:user:export')")
    @Log(title = "App用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdUser mdUser)
    {
        List<MdUser> list = mdUserService.selectMdUserList(mdUser);
        ExcelUtil<MdUser> util = new ExcelUtil<MdUser>(MdUser.class);
        util.exportExcel(response, list, "App用户数据");
    }

    /**
     * 获取App用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('push:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mdUserService.selectMdUserById(id));
    }

    /**
     * 新增App用户
     */
    @PreAuthorize("@ss.hasPermi('push:user:add')")
    @Log(title = "App用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdUser mdUser)
    {
        return toAjax(mdUserService.insertMdUser(mdUser));
    }

    /**
     * 修改App用户
     */
    @PreAuthorize("@ss.hasPermi('push:user:edit')")
    @Log(title = "App用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdUser mdUser)
    {
        return toAjax(mdUserService.updateMdUser(mdUser));
    }

    /**
     * 删除App用户
     */
    @PreAuthorize("@ss.hasPermi('push:user:remove')")
    @Log(title = "App用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mdUserService.deleteMdUserByIds(ids));
    }
}
